package implement;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.persistence.EntityManager;

import persistence.JPAUtil;
import dao.ChamadoDAO;
import model.Chamado;
import generics.ImpGenericDAO;

public class ChamadoDAOImpl extends ImpGenericDAO<Chamado, Long> implements ChamadoDAO{

	Date hoje = new Date();
	EntityManager em = JPAUtil.getEntityManager();
	
	@Override
	public String geraCodigo() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
		return sdf.format(hoje);
	}

	@Override
	public Date geraData() {
		return hoje;
	}

	@Override
	public List<Chamado> chamadosUpas() {
		StringBuilder sql = new StringBuilder();
		sql.append("Select c From Chamado c WHERE c.equipamento.unidade.tipoUnidade = 1");
		return em.createQuery(sql.toString()).getResultList();
	}

	@Override
	public List<Chamado> chamadosPostos() {
		StringBuilder sql = new StringBuilder();
		sql.append("Select c From Chamado c WHERE c.equipamento.unidade.tipoUnidade = 0");
		return em.createQuery(sql.toString()).getResultList();
	}

	@Override
	public List<Chamado> chamadosAguardando() {
		StringBuilder sql = new StringBuilder();
		sql.append("Select c From Chamado c WHERE c.status = 0");
		return em.createQuery(sql.toString()).getResultList();
	}

	@Override
	public List<Chamado> chamadosAtendidos() {
		StringBuilder sql = new StringBuilder();
		sql.append("Select c From Chamado c WHERE c.status = 1");
		return em.createQuery(sql.toString()).getResultList();
	}

	@Override
	public List<Chamado> chamadosAtrasados() {
		StringBuilder sql = new StringBuilder();
		sql.append("Select c From Chamado c WHERE c.status = 2");
		return em.createQuery(sql.toString()).getResultList();
	}

	@Override
	public void atribuir(Chamado chamado) {
		//falta implementar
		
	}
	
	

}
